package com.usercon.userconter.service;

import com.usercon.userconter.Utils.MD5Util;
import com.usercon.userconter.mapper.UserMapper;
import com.usercon.userconter.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    //查找所有用户
    public List<User> findAll(){
        System.out.println("UserService已调用 返回值:" + userMapper.getUserList());
        return userMapper.getUserList();
    }

    //根据ID查找用户
    public User findById(int id) {
        return userMapper.getUserById(id);
    }

    //添加用户
    public int addUser(int id,String username,String password){
        String passMD5 = MD5Util.MD5Encode(password,"UTF-8");
        return userMapper.addUser(id,username,passMD5);
    }

    //修改用户信息
    public int updateUser(User user){
        return userMapper.updateUser(user);
    }

    //删除用户
    public Integer deleteUser(int id){
        return userMapper.deleteUser(id);
    }

    //获取状态码
    public Integer userStatus(int id){
        return userMapper.userStatus(id);
    }

    //获取密码
    public String getPass(int id){return userMapper.getPass(id);}

    //更改密码
    public Integer updatePass(int id,String password){
        return userMapper.updatePass(id,password);
    }

    //登录判断  现有问题   密码未经过加密的账户信息登录验证出错 原因到service层时密码会统一加密
    // 已解决 逻辑用if else嵌套实现 后续待继续优化
    public User login(String lUser,String lPass){
        return userMapper.login(lUser,lPass);
    }

}
